package com.ipet.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ipet.common.utils.PageUtils;
import com.ipet.common.utils.R;
import com.ipet.modules.sys.entity.PetChargesEntity;
import com.ipet.modules.sys.service.PetChargesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 收费管理
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-04-23 17:42:13
 */
@RestController
@RequestMapping("sys/petcharges")
public class PetChargesController {
    @Autowired
    private PetChargesService petChargesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:petcharges:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = petChargesService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:petcharges:info")
    public R info(@PathVariable("id") Integer id){
			PetChargesEntity petCharges = petChargesService.selectById(id);

        return R.ok().put("petCharges", petCharges);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:petcharges:save")
    public R save(@RequestBody PetChargesEntity petCharges){
        petCharges.setCreateTime(new Date());
			petChargesService.insert(petCharges);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:petcharges:update")
    public R update(@RequestBody PetChargesEntity petCharges){
			petChargesService.updateById(petCharges);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:petcharges:delete")
    public R delete(@RequestBody Integer[] ids){
			petChargesService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 统计列表
     */
    @RequestMapping("/statistics")
    @RequiresPermissions("sys:petcharges:list")
    public R statistics(){
        List<Map<String,Object>> list = petChargesService.getStatistics();
        return R.ok().put("list", list);
    }

    /**
     * 统计(月份)列表
     */
    @RequestMapping("/statistics/months")
    @RequiresPermissions("sys:petcharges:list")
    public R statisticsMonths(){
        List<Map<String,Object>> list = petChargesService.getStatisticsByMonths();
        return R.ok().put("list", list);
    }

}
